home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Embed / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  12.0 KB  |  397 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Embed.hpp"
  13.  
  14. #ifndef FRAME_H
  15. #include "Frame.h"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef PROXY_H
  23. #include "Proxy.h"
  24. #endif
  25.  
  26. #ifndef COMMAND_H
  27. #include "Command.h"
  28. #endif
  29.  
  30. #ifndef CONTENT_H
  31. #include "Content.h"
  32. #endif
  33.  
  34. #ifndef SELECT_H
  35. #include "Select.h"
  36. #endif
  37.  
  38. #ifndef DEFINES_K
  39. #include "Defines.k"
  40. #endif
  41.  
  42. // ----- Framework Includes -----
  43.  
  44. #ifndef FWUTIL_H
  45. #include "FWUtil.h"
  46. #endif
  47.  
  48. #ifndef FWCONTXT_H
  49. #include "FWContxt.h"
  50. #endif
  51.  
  52. #ifndef FWPRESEN_H
  53. #include "FWPresen.h"
  54. #endif
  55.  
  56. #ifndef FWPXYFRM_H
  57. #include "FWPxyFrm.h"
  58. #endif
  59.  
  60. #ifndef FWGROWBX_H
  61. #include "FWGrowBx.h"
  62. #endif
  63.  
  64. #ifndef FWSCLBAR_H
  65. #include "FWSclBar.h"
  66. #endif
  67.  
  68. // ----- OS Layer Includes -----
  69.  
  70. #ifndef FWODGEOM_H
  71. #include "FWODGeom.h"
  72. #endif
  73.  
  74. #ifndef FWRECSHP_H
  75. #include "FWRecShp.h"
  76. #endif
  77.  
  78. #ifndef FWMNUBAR_H
  79. #include "FWMnuBar.h"
  80. #endif
  81.  
  82. // ----- OpenDoc Includes -----
  83.  
  84. #ifndef SOM_Module_OpenDoc_Commands_defined
  85. #include <CmdDefs.xh>
  86. #endif
  87.  
  88. #ifndef SOM_Module_OpenDoc_StdProps_defined
  89. #include <StdProps.xh>
  90. #endif
  91.  
  92. //========================================================================================
  93. //    Runtime information
  94. //========================================================================================
  95.  
  96. #ifdef FW_BUILD_MAC
  97. #pragma segment odfembed
  98. #endif
  99.  
  100. FW_DEFINE_AUTO(CEmbedFrame)
  101.  
  102. //========================================================================================
  103. //    Constant
  104. //========================================================================================
  105.  
  106. const FW_Fixed kBorder = FW_IntToFixed(15);
  107. const FW_Fixed kHalfBorder = FW_IntToFixed(8);
  108.  
  109. //========================================================================================
  110. //    CLASS CEmbedFrame
  111. //========================================================================================
  112.  
  113. //----------------------------------------------------------------------------------------
  114. //     CEmbedFrame::CEmbedFrame
  115. //----------------------------------------------------------------------------------------
  116.  
  117. CEmbedFrame::CEmbedFrame(Environment* ev, 
  118.                         ODFrame* odFrame, 
  119.                         FW_CPresentation* presentation, 
  120.                         CEmbedPart* part,
  121.                         CEmbedContent* content) :
  122.     FW_CEmbeddingFrame(ev, odFrame, presentation, part),
  123.     FW_MDraggableFrame(ev, this),
  124.     FW_MDroppableFrame(ev, this),
  125.     fPart(part),
  126.     fContent(content)
  127. {
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //     CEmbedFrame::~CEmbedFrame
  132. //----------------------------------------------------------------------------------------
  133.  
  134. CEmbedFrame::~CEmbedFrame()
  135. {
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //     CEmbedFrame::Draw
  140. //----------------------------------------------------------------------------------------
  141.  
  142. void CEmbedFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  143. {
  144.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  145.  
  146.     FW_CRectShape::RenderRect(vc, GetBounds(ev), FW_kFill, FW_kRGBBlue);
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. //     CEmbedFrame::Draw
  151. //----------------------------------------------------------------------------------------
  152.  
  153. void CEmbedFrame::CreateSubViews(Environment* ev)
  154. {        
  155.     // ----- Create a GrowBox only in root frame
  156.     //         Note:     You do not need CreateSubViews if the views are defined in resources.
  157.     //                See the Container or Form samples
  158.     
  159.     if (this->IsRoot(ev)) 
  160.     {
  161.         FW_CRect frameRect = GetBounds(ev);  
  162.         FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  163.         frameRect.right -= sbSize.x;
  164.         frameRect.bottom -= sbSize.y;
  165.         
  166.         FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, frameRect.BotRight());
  167.     }
  168.  
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. //    CEmbedFrame::CanAcceptDrop
  173. //----------------------------------------------------------------------------------------
  174. // As an embedding frame I can accept anything
  175.  
  176. ODDragResult CEmbedFrame::CanAcceptDrop(Environment *ev, ODDragItemIterator* dragInfo)
  177. {
  178.     return TRUE;
  179. }
  180.  
  181. //---------------------------------------------------------------------------------------
  182. //    CEmbedFrame::DoAdjustMenus
  183. //---------------------------------------------------------------------------------------
  184.  
  185. FW_Boolean CEmbedFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  186. {
  187.     if (hasMenuFocus)
  188.     {
  189.         // Check clipboard for a part to paste
  190.         menuBar->EnableCommand(ev, kODCommandPaste, HasPropertyOnClipboard(ev, kODPropContentFrame, NULL));
  191.     
  192.         // If an embedded part is selected, change Copy menu item to "Copy Part"
  193.         if (GetPresentation(ev)->GetSelection(ev)->IsEmpty(ev))
  194.             menuBar->SetItemString(ev, kODCommandCopy, FW_CString32("Copy"));
  195.         else
  196.             menuBar->SetItemString(ev, kODCommandCopy, FW_CString32("Copy Part"));
  197.     }
  198.     
  199.     return FALSE;
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. //    CEmbedFrame::MakeFrameShape
  204. //----------------------------------------------------------------------------------------
  205. //    Returns a new shape equals to my frame shape inset by eight pixels. Otherwise I can't drop 
  206. //    anything
  207.  
  208. ODShape* CEmbedFrame::MakeFrameShape(Environment* ev)
  209. {
  210.     FW_CRect bounds = GetBounds(ev);
  211.     bounds.Inset(kBorder);
  212.     bounds.Place(FW_kFixed0, FW_kFixed0);        // Frame shape always zero based
  213.     return ::FW_NewODShape(ev, bounds);
  214. }
  215.  
  216. //----------------------------------------------------------------------------------------
  217. //    CEmbedFrame::CreateOneEmbeddedFacet
  218. //----------------------------------------------------------------------------------------
  219.  
  220. ODFacet* CEmbedFrame::CreateOneEmbeddedFacet(Environment* ev, 
  221.                                         ODFacet* embeddingFacet, 
  222.                                         ODFrame* embeddedFrame, 
  223.                                         ODFacet* sibling,
  224.                                         const FW_CRect& clipRect)
  225. {
  226.     FW_CAcquiredODTransform externalTransform = ::FW_NewODTransform(ev, FW_CPoint(kBorder, kBorder));
  227.     FW_CAcquiredODShape clipShape = ::FW_NewODShape(ev, clipRect);
  228.     
  229.     return embeddingFacet->CreateEmbeddedFacet(ev,
  230.                                                 embeddedFrame,
  231.                                                 clipShape,
  232.                                                 externalTransform,
  233.                                                 NULL,                    // Canvas
  234.                                                 NULL,                    // biasCanvas
  235.                                                 sibling,                // siblingFacet
  236.                                                 kODFrameInFront);
  237. }
  238.  
  239. //----------------------------------------------------------------------------------------
  240. //    CEmbedFrame::EmbeddedFacetBounds
  241. //----------------------------------------------------------------------------------------
  242.  
  243. void CEmbedFrame::EmbeddedFacetBounds(Environment* ev, FW_CRect* clipRects)
  244. {
  245.     FW_CRect bounds = GetBounds(ev);
  246.     bounds.Place(FW_kFixed0, FW_kFixed0);
  247.     bounds.Inset(kBorder);
  248.  
  249.     FW_CRect embeddedBounds = bounds;
  250.     embeddedBounds.Place(FW_kFixed0, FW_kFixed0);
  251.  
  252.     FW_CPoint embeddedMiddle(FW_Half(embeddedBounds.left + embeddedBounds.right), FW_Half(embeddedBounds.top + embeddedBounds.bottom));
  253.     
  254.     FW_CPoint middle(FW_Half(bounds.left + bounds.right), FW_Half(bounds.top + bounds.bottom));
  255.  
  256.     clipRects[0].Set(FW_kFixed0, FW_kFixed0, embeddedMiddle.x - kHalfBorder, embeddedMiddle.y - kHalfBorder);
  257.     clipRects[1].Set(embeddedMiddle.x + kHalfBorder, FW_kFixed0, embeddedBounds.right, embeddedMiddle.y - kHalfBorder);
  258.     clipRects[2].Set(FW_kFixed0, embeddedMiddle.y + kHalfBorder, embeddedMiddle.x - kHalfBorder, embeddedBounds.bottom);
  259.     clipRects[3].Set(embeddedMiddle.x + kHalfBorder, embeddedMiddle.y + kHalfBorder, embeddedBounds.right, embeddedBounds.bottom);
  260. }
  261.  
  262. //----------------------------------------------------------------------------------------
  263. //    CEmbedFrame::CreateEmbeddedFacet
  264. //----------------------------------------------------------------------------------------
  265.  
  266. ODFacet* CEmbedFrame::CreateEmbeddedFacet(Environment* ev,
  267.                                         ODFacet* embeddingFacet,
  268.                                         FW_MProxy* proxy,
  269.                                         ODFrame* embeddedFrame,
  270.                                         ODShape* proposedClipShape)
  271. {
  272.     FW_CRect bounds = GetBounds(ev);
  273.     bounds.Place(FW_kFixed0, FW_kFixed0);
  274.     bounds.Inset(kBorder);
  275.  
  276.     FW_CRect embeddedBounds = bounds;
  277.     embeddedBounds.Place(FW_kFixed0, FW_kFixed0);
  278.  
  279.     if (fPart->FacetNumber() == cOneFacet)
  280.     {
  281.         return CreateOneEmbeddedFacet(ev, embeddingFacet, embeddedFrame, NULL, embeddedBounds);
  282.     }
  283.     else
  284.     {
  285.         FW_CRect clipRects[4];
  286.         EmbeddedFacetBounds(ev, clipRects);
  287.         
  288.         ODFacet* siblingFacet = NULL;
  289.         
  290.         siblingFacet = CreateOneEmbeddedFacet(ev, 
  291.                                 embeddingFacet, 
  292.                                 embeddedFrame, 
  293.                                 siblingFacet,
  294.                                 clipRects[0]);
  295.         CreateOneEmbeddedFacet(ev, 
  296.                                 embeddingFacet, 
  297.                                 embeddedFrame, 
  298.                                 siblingFacet,
  299.                                 clipRects[1]);
  300.         CreateOneEmbeddedFacet(ev, 
  301.                                 embeddingFacet, 
  302.                                 embeddedFrame, 
  303.                                 siblingFacet,
  304.                                 clipRects[2]);
  305.         return CreateOneEmbeddedFacet(ev, 
  306.                                 embeddingFacet, 
  307.                                 embeddedFrame, 
  308.                                 siblingFacet,
  309.                                 clipRects[3]);
  310.     }
  311. }
  312.  
  313. //----------------------------------------------------------------------------------------
  314. //    CEmbedFrame::FrameShapeChanged
  315. //----------------------------------------------------------------------------------------
  316. //    Change the frame shape of the embedded frame to be the same as mine minus a border
  317.  
  318. void CEmbedFrame::FrameShapeChanged(Environment* ev)
  319. {
  320.     // Must call inherited so our "view" superclass gets adjusted.
  321.     FW_CFrame::FrameShapeChanged (ev);
  322.     
  323.     CEmbedProxy* proxy = fContent->GetProxy();
  324.     if (proxy != NULL)
  325.     {
  326.         FW_CAcquiredODFrame embeddedFrame = proxy->AcquireEmbeddedFrame(ev, this);
  327.         
  328.         FW_CAcquiredODShape frameShape = MakeFrameShape(ev);
  329.         embeddedFrame->ChangeFrameShape(ev, frameShape, NULL);
  330.     }
  331. }
  332.  
  333. //----------------------------------------------------------------------------------------
  334. //    CEmbedFrame::NewClipboardCommand
  335. //----------------------------------------------------------------------------------------
  336.  
  337. FW_CClipboardCommand* CEmbedFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  338. {
  339.     FW_Boolean undoAble = TRUE;
  340.     if (commandID == kODCommandPasteAs)
  341.         undoAble = FALSE;
  342.  
  343.     return FW_NEW(CEmbedEditCommand, (ev, 
  344.                                         commandID,
  345.                                         fContent,
  346.                                         this,
  347.                                         GetPresentation(ev)->GetSelection(ev),
  348.                                         undoAble));
  349. }
  350.  
  351. //----------------------------------------------------------------------------------------
  352. //    CEmbedFrame::NewDropCommand
  353. //----------------------------------------------------------------------------------------
  354.  
  355. FW_CDropCommand* CEmbedFrame::NewDropCommand(Environment* ev,
  356.                                              FW_CFrame* frame,
  357.                                              ODDragItemIterator* dropInfo, 
  358.                                              ODFacet* odFacet, 
  359.                                              const FW_CPoint& dropPoint)
  360. {
  361.     return FW_NEW(CEmbedDropCommand, (ev, fContent, this, dropInfo, odFacet, dropPoint));
  362. }
  363.  
  364. //----------------------------------------------------------------------------------------
  365. //    CEmbedFrame::NewDragCommand
  366. //----------------------------------------------------------------------------------------
  367.  
  368. FW_CDragCommand* CEmbedFrame::NewDragCommand(Environment *ev, FW_CFrame* theFrame, const FW_CMouseEvent& theMouseEvent)
  369. {
  370. FW_UNUSED(theMouseEvent);
  371.     
  372.     return FW_NEW(CEmbedDragCommand, (ev, fContent, this, (CEmbedSelection*)GetPresentation(ev)->GetSelection(ev)));
  373. }
  374.  
  375. //----------------------------------------------------------------------------------------
  376. //    CEmbedFrame::NewInsertCommand
  377. //----------------------------------------------------------------------------------------
  378. FW_CInsertCommand* CEmbedFrame::NewInsertCommand(Environment* ev, const FW_PFileSpecification& fileSpec)
  379. {
  380.     return FW_NEW(CEmbedInsertCommand, (ev,
  381.                                         this,
  382.                                         fileSpec,
  383.                                         fContent));
  384. }
  385.  
  386. //----------------------------------------------------------------------------------------
  387. // CEmbedFrame::DoMouseDownInEmbeddedFrameBorder
  388. //----------------------------------------------------------------------------------------
  389.  
  390. FW_Boolean CEmbedFrame::DoMouseDownInEmbeddedFrameBorder(Environment *ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
  391. {    
  392.     Drag(ev, theBorderMouseEvent);
  393.     
  394.     return TRUE;
  395. }
  396.  
  397.